function globalListener() {
	let that = this;
	let packageNames = [];
	if (brand == 'huawei') {
		packageNames = ['com.huawei.systemmanager', 'com.huawei.android.launcher']
	} else if (brand == 'xiaomi') {
		packageNames = ['com.miui.securitycenter', 'com.miui.home']
	} else if (brand == 'vivo') {
		packageNames = ['com.vivo.permissionmanager', 'com.bbk.launcher2']
	}
	let timer = null;
	LinAccessibility.start({
			packageNames: packageNames,
			notificationTimeout: 20,
			monitorAllEvent: false,
		},
		response => {
			console.log(response);
			if (timer) clearTimeout(timer);
			timer = setTimeout(async () => {
				timer = null;
				// huawei 锁定后台
				if (response.accNode.packageName == 'com.huawei.android.launcher') {
					// 获取是否存在锁定状态
					let isDescFound = LinAccessibility
						.findFirstNodeByContentDesc('已锁定guardApp');
					if (!isDescFound) {
						// 锁定任务栏
						that.lockActionSheet();
					}
				} else if (response.accNode.packageName == 'com.miui.home') {
					let isDescFound = LinAccessibility
						.findFirstNodeByContentDesc('guardApp,已加锁');
					console.log(!isDescFound);
					if (!isDescFound) {
						// 锁定任务栏
						that.lockActionSheet();
					}
				} else if (response.accNode.packageName == 'com.bbk.launcher2') {
					let isDescFound = LinAccessibility
						.findFirstNodeByContentDesc('guardApp已锁定-下拉菜单');
					if (!isDescFound) {
						// 锁定任务栏
						that.lockActionSheet()
					}
				}
			}, 500)
		}
	);
}

async function startBackstage() {
	let recentTasksOpened = LinAccessibility.goRecentTasks();
	console.log('Recent tasks opened: ', recentTasksOpened);
	if (recentTasksOpened) {
		this.setTodoStep('锁定后台', true);
		this.step = 2;
		await delayedFunction(this.swipeTheScreen);
		await delayedFunction(this.lockActionSheet);
		await delayedFunction(() => {
			LinAccessibility.clickLocation(
				(width / 2) * systemInfo.pixelRatio,
				(height / 2) * systemInfo.pixelRatio
			);
		});
	}
}


// 横向滑动屏幕
function swipeTheScreen() {
	console.log(width * systemInfo.pixelRatio - 40 * systemInfo.pixelRatio, 50 * systemInfo.pixelRatio,
		'横向滑动屏幕');
	LinAccessibility.slideScreen(
		width * systemInfo.pixelRatio - 40 * systemInfo.pixelRatio,
		(height / 2) * systemInfo.pixelRatio,
		50 * systemInfo.pixelRatio,
		(height / 2) * systemInfo.pixelRatio,
		200);
}

// 检测是否在电池优化列表中
function isIgnoringBatteryOptimizations() {
	if (uni.getSystemInfoSync().platform === 'android') {
		const powerManager = plus.android.importClass('android.os.PowerManager');
		const mainActivity = plus.android.runtimeMainActivity();
		const pm = mainActivity.getSystemService(powerManager.class);
		const packageName = mainActivity.getPackageName();
		return pm.isIgnoringBatteryOptimizations(packageName);
	}
	return false;
}
// 请求忽略电池优化
function requestIgnoreBatteryOptimizations() {
	if (uni.getSystemInfoSync().platform === 'android') {
		const Intent = plus.android.importClass('android.content.Intent');
		const Settings = plus.android.importClass('android.provider.Settings');
		const mainActivity = plus.android.runtimeMainActivity();
		const packageName = mainActivity.getPackageName();
		const intent = new Intent();
		if (uni.getSystemInfoSync().brand == 'huawei') {
			intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
		} else {
			intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
		}

		const Uri = plus.android.importClass('android.net.Uri');
		intent.setData(Uri.parse('package:' + packageName));
		mainActivity.startActivity(intent);

	}
}

function openBatteryUsage() {
	if (plus.os.name === 'Android') {
		var Intent = plus.android.importClass('android.content.Intent');
		var Settings = plus.android.importClass('android.provider.Settings');
		var Uri = plus.android.importClass('android.net.Uri');
		var mainActivity = plus.android.runtimeMainActivity();

		var intent = new Intent();
		intent.setAction(Intent.ACTION_VIEW);
		var uri = Uri.parse("package:" + plus.runtime.appid);
		intent.setData(uri);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

		try {
			mainActivity.startActivity(intent);
		} catch (e) {
			console.error("Error opening battery usage: " + e.message);
		}
	} else {
		console.log("This function is only supported on Android.");
	}
}